package com.yootk.main;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.env.*;

import java.util.Arrays;
import java.util.Map;
import java.util.Properties;

public class PropertyDemo {
    private static final Logger LOGGER = LoggerFactory.getLogger(PropertyDemo.class);
    public static void main(String[] args) {
        Map<String, Object> data = Map.of("yootk", "www.yootk.com",
                "jixianit", "www.jixianit.com"); // Java层次上的集合管理
        PropertySource mapSource = new MapPropertySource("url", data); // 资源管理
        Properties prop = new Properties();
        prop.setProperty("java", "Java进阶开发实战");
        prop.setProperty("spring", "Spring开发实战");
        PropertySource propSource = new PropertiesPropertySource("book", prop); // 属性源
        MutablePropertySources sources = new MutablePropertySources();
        sources.addLast(mapSource); // 追加属性源管理
        sources.addLast(propSource); // 追加属性源管理
        PropertySourcesPropertyResolver resolver = new PropertySourcesPropertyResolver(sources) ;
        LOGGER.info("资源表达式解析处理：{}",resolver.resolvePlaceholders("${yootk}"));
        LOGGER.info("资源表达式解析处理：{}",resolver.resolvePlaceholders("${java}"));
        LOGGER.info("资源表达式解析处理：{}",resolver.resolvePlaceholders("${lee}"));
    }
}